Skip to content

Conversation

@odysseus0
Copy link
Contributor

@odysseus0 odysseus0 commented Oct 12, 2025

Summary

Support header-based URL forwarding from proxyd Stage 2.

If X-Original-Path header is present, reconstruct URL from headers. Otherwise fall back to r.URL (backward compatible).

Motivation

This enables clean separation between public API paths and internal service endpoints:

  • Public API paths like /fast are request metadata, not REST resources
  • Proxyd forwards these as X-Original-Path and X-Original-Query headers
  • Internal services can serve at consistent endpoints (e.g., /api)
  • Backward compatible: if headers absent, uses r.URL as before

Changes

  • Modified ServeHTTP in rpcserver/jsonrpc_server.go to check for X-Original-Path header
  • If header present, reconstructs URL from X-Original-Path and X-Original-Query
  • Otherwise uses r.URL (existing behavior)
  • Added comprehensive tests verifying both Stage 1 and Stage 2 work correctly

Testing

go test ./rpcserver/... -v

All tests pass including new TestURLExtraction which verifies:

  • Stage 1: Direct URL paths work (no headers)
  • Stage 2: Header-based URLs work
  • Headers take precedence when present

Support header-based URL forwarding from proxyd Stage 2.
If X-Original-Path header is present, reconstruct URL from headers.
Otherwise fall back to r.URL (backward compatible).

This enables clean separation between public API paths and internal
service endpoints while maintaining consistency with other services.

Context:
- Public API paths like /fast are request metadata, not REST resources
- Proxyd forwards these as X-Original-Path/Query headers
- Internal services can serve at consistent endpoints (e.g., /api)
- Backward compatible: if headers absent, uses r.URL as before
Proxyd may send X-Original-Path and X-Original-Query headers independently:
- Only X-Original-Query when path is / (root)
- Only X-Original-Path when there's no query string

Updated logic to selectively replace path and query instead of
requiring both headers to be present together.

Added tests for edge cases.
Added explicit test per Tymur's requirement that simple methods should
work with /fast, /whatever, and any other path - not just hardcoded paths.

Tests /whatever, /anything, /custom-path, /v1/special to demonstrate
the implementation is path-agnostic.
Consolidated from 6 to 4 tests with maximum value density:
- Backward compatibility (no headers)
- Both headers with arbitrary path (/whatever proves not hardcoded)
- Edge case: only query header
- Edge case: only path header

Removed redundant tests while maintaining full coverage.
@odysseus0 odysseus0 merged commit a411fd8 into main Oct 12, 2025
2 checks passed
@odysseus0 odysseus0 deleted the feat/stage2-url-header-extraction branch October 12, 2025 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant